<template>
  <div class="app-container">
    <!-- <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="公告标题" prop="noticeTitle">
        <el-input
          v-model="queryParams.noticeTitle"
          placeholder="请输入公告标题"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作人员" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入操作人员"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="noticeType">
        <el-select
          v-model="queryParams.noticeType"
          placeholder="公告类型"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in sys_notice_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->
    <el-row :gutter="24" v-if="softwareList.length > 0">
      <el-col
        :span="6"
        v-for="item in softwareList"
        :key="item.id"
        style="margin-top: 20px"
      >
        <el-card class="software-card" shadow="never">
          <template #header>
            <span class="soft-title">{{ item.name }}</span>
          </template>
          <p>
            <el-button class="soft-link" @click="jumpLink(item.url)">
              点击前往
            </el-button>

            <span
              :class="{
                'color-red': item.isContent == 0,
                'color-green': item.isContent == 1,
              }"
              >{{ item.isContent == 1 ? "已联通" : "未连通" }}</span
            >
          </p>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="24" v-else>
      <el-col style="text-align:center">暂无公开工具</el-col>
    </el-row>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <Software
      v-model="dialogVisible"
      @confirm="submit"
      :currentSoftId="currentSoftId"
    ></Software>
  </div>
</template>

<script setup name="Project">
import { getSoftwareListForeUser, updateSoftware } from "@/api/system/software";
import { addNotice, delNotice, editForTop } from "@/api/pms/project";
import { addBanner } from "@/api/system/banner";
import Software from "./components/softwareDialog.vue";
const route = useRoute();
const router = useRouter();

const { proxy } = getCurrentInstance();
const { sys_notice_status, sys_notice_type } = proxy.useDict(
  "sys_notice_status",
  "sys_notice_type"
);

const softwareList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dialogVisible = ref(false);
const currentSoftId = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageDomain: {
      isAsc: "true",
      orderByColumn: "",
      pageNum: 1,
      pageSize: 10,
    },
    title: "",
  },
  rules: {
    noticeTitle: [
      { required: true, message: "公告标题不能为空", trigger: "blur" },
    ],
    noticeType: [
      { required: true, message: "公告类型不能为空", trigger: "change" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询公告列表 */
function getList() {
  loading.value = true;
  getSoftwareListForeUser(queryParams.value).then((response) => {
    softwareList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    noticeId: undefined,
    noticeTitle: undefined,
    noticeType: undefined,
    noticeContent: undefined,
    status: "0",
  };
  proxy.resetForm("noticeRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  // open.value = true;
  // title.value = "添加公告";
  currentSoftId.value = "";
  dialogVisible.value = true;
}

/**修改按钮操作 */
function handleUpdate(row) {
  reset();
  currentSoftId.value = row.id;
  dialogVisible.value = true;
}

/**跳转活动详情 */
function goDetail(row) {
  reset();
  // const noticeId = row.noticeId || ids.value;
  // getNotice(noticeId).then((response) => {
  //   form.value = response.data;
  //   open.value = true;
  //   title.value = "修改公告";
  // });
  router.push({ path: `detail/${row.id}` });
}

function submit(formData) {
  updateSoftware(formData).then((response) => {
    proxy.$modal.msgSuccess("新增成功");
    getList();
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const noticeIds = row.id ? [row.id] : ids.value;
  proxy.$modal
    .confirm("是否确认删除")
    .then(function () {
      return delNotice(noticeIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

//置顶
function handleTop(row) {
  let params = {
    id: row.id,
    isTop: row.isTop == "1" ? "0" : "1",
  };
  editForTop(params).then((res) => {
    proxy.$modal.msgSuccess("修改成功");
    getList();
  });
}
//跳转外链
function jumpLink(url) {
  window.open(url);
}
onMounted(() => {
  getList();
});

// watch(
//   () => props.projectId,
//   (newId, oldId) => {
//     if (newId) {
//       debugger
//       queryParams.value.id = props.projectId;
//       getList();
//     }
//   },
//   { deep: true, immediate: true }
// );
</script>
<style lang="scss" scoped>
.soft-title {
  padding-left: 5px;
  font-weight: bold;
}
.soft-link {
  border-radius: 100px;
}
.color-red {
  color: red;
  position: relative;
  font-size: 14px;
  &::before {
    content: "";
    width: 7px;
    height: 7px;
    background: red;
    border-radius: 20px;
    position: absolute;
    left: -15px;
    top: 5px;
  }
}
.color-green {
  color: green;
  position: relative;
  font-size: 14px;
  &::before {
    content: "";
    width: 7px;
    height: 7px;
    background: green;
    border-radius: 20px;
    position: absolute;
    left: -15px;
    top: 5px;
  }
}
.software-card {
  p {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  :deep(.el-card__header) {
    padding: 15px 20px !important;
  }
  :deep(.el-card__body) {
    padding-bottom: 10px !important;
  }
}
</style>
